package com.yyn.pigeon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyn.pigeon.config.exceptionhandler.CustomException;
import com.yyn.pigeon.entity.User;
import com.yyn.pigeon.mapper.UserMapper;
import com.yyn.pigeon.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户信息 服务实现类
 * </p>
 *
 * @author yyn
 * @since 2023-03-15
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Boolean register(User user) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getPhone, user.getPhone());
        if (userMapper.selectCount(lambdaQueryWrapper) > 0) {
            return false;
        } else {
            userMapper.insert(user);
            return true;
        }

    }

    @Override
    public User login(User user) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(User::getPhone, user.getPhone());
        User user1 = userMapper.login(user.getPhone(), user.getPassword());
        return user1;
    }
}
